package com.yt.website.util;

import com.sun.jmx.snmp.agent.SnmpMibSubRequest;
import com.yt.util.HttpClientUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.net.URLEncoder;

/**
 * Created by liujunshi on 16/2/22.
 */
public class SmsUtil {
    private static Log logger = LogFactory.getLog(SmsUtil.class);
    private static final String URL_BY_MD_YITIAN="http://sdk2.zucp.net:8060/webservice.asmx/SendSMS";
    private static final String[] PARAM_MD_YITIAN   = {"sn=SDK-HGG-010-00022&pwd=605645&mobile=",
            "&content="};

    public static boolean send(String sms, String mobile){
        try {
            String suffix = "【怡天网】";
            StringBuilder sbByMD = new StringBuilder()
                    .append(PARAM_MD_YITIAN[0])
                    .append(mobile)
                    .append(PARAM_MD_YITIAN[1])
                    .append(URLEncoder.encode(sms + suffix, "GB2312"));
            String result = HttpClientUtil.sendHttpGetRequest(URL_BY_MD_YITIAN + "?" + sbByMD.toString());
            if(result == null || result.startsWith("-")){
                logger.error("Send SMS ERROR:"+ ";ErrorCode:" + result);
                return false;
            }
        }catch(Exception ex){
            logger.error(ex.getMessage(), ex);
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        SmsUtil.send("验证码是1232", "18610178193");
    }
}
